package com.ewe.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ewe.domain.WarehouseNetwork;
import com.ewe.domain.common.Result;
import com.ewe.retrofit.EbayClient;
import com.ewe.service.WarehouseNetworkService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Levin
 */
@Slf4j
@ApiSupport(author = "Levin.Tang")
@Api(tags = "网络仓")
@RestController
@RequestMapping("/warehouse_networks")
@RequiredArgsConstructor
public class WarehouseNetworkController {

    private final WarehouseNetworkService warehouseNetworkService;
    private final EbayClient ebayClient;

    @GetMapping
    @ApiOperation(value = "测试查接口 - [DONE]", notes = "查询EBay网络仓数据")
    @ApiImplicitParam(name = "action", value = "查询条件-模糊匹配")
    public Result<List<WarehouseNetwork>> query(String action) {
        final String token = ebayClient.getToken();
        log.info("token info - {}", token);
        return Result.success(warehouseNetworkService.list(Wrappers.<WarehouseNetwork>lambdaQuery()
                .eq(action != null, WarehouseNetwork::getAction, action)));
    }


}
